<?php
class Shop_Model_Observer_AttacheAttribsValuesToProduct extends Promotor_Observable_Observer_Abstract {
	public function update(Promotor_Observable_List $list, $productId = null) {
		$rq = $this->getRequest();

		if ((null === ($attribs = $rq->getPost('attribs')))) {
			$this->_setStatus(self::NULL);
			return;
		}
		if (is_array($productId)) {
			$productId = isset($productId['id'])
				? $productId['id']
				: current($productId);
		}

		if (null === $productId) {
			$this->_setStatus(self::NULL);
			return;
		}

		$model = new Shop_Model_AttrValue();
		$model->attacheAttribsValuesToProduct($productId, (array) $attribs);

		$status = $model->getStatus();

		$this->_setStatus($status);
		$this->_setMessages($model->getMessages(false));
		$this->_exception = $model->getExceptions();
	}
}